package com.luo.ai.assistant.web;

import com.luo.ai.assistant.chat.ChatRagService;
import com.luo.ai.assistant.chat.MyChatRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.stream.Stream;

/**
 * Chat Controller
 *
 * @author luohq
 * @date 2025-01-02
 */
@RestController
@RequestMapping("/ai/chat")
class ChatController {

    private Logger log = LoggerFactory.getLogger(ChatController.class);

    /**
     * Chat With Rag服务
     */
    private ChatRagService chatRagService;

    public ChatController(ChatRagService chatRagService) {
        this.chatRagService = chatRagService;
    }

    @GetMapping
    public String chat(@RequestParam String userInput) {
        return this.chatRagService.chat(userInput);
    }

    @GetMapping("/stream")
    public Flux<String> chatStream(@RequestParam String userInput) {
        return this.chatRagService.chatStream(userInput);
        //return this.mockStreamResp();
    }

    @GetMapping("/rag")
    public String chatRag(MyChatRequest myChatRequest) {
        return this.chatRagService.chatRag(myChatRequest);
    }

    @GetMapping("/rag/stream")
    public Flux<String> chatRagStream(MyChatRequest myChatRequest) {
        return this.chatRagService.chatRagStream(myChatRequest);
        //return this.mockStreamResp();
    }

    Flux<String> mockStreamResp() {
        return Flux.fromStream(Stream.of(
                "好的，我明白了。你希望我根据C4模型中的C1级别图来为你绘制一个上下文图。",
                "C1级别的图主要描述系统的高层视图，包括系统本身、用户和其他相关系统之间的交互。 ",
                "由于你没有提供具体的上下文信息（如系统名称、用户类型、外部系统等），我将创建一个通用的示例。",
                "如果你能提供更多具体信息，我可以进一步定制化这个图。 \n",
                "### C1 级别上下文图- 示例 \n",
                "####系统名称：在线购物平台 \n **参与者 (Actors):** "
                ));
    }

}